<template>
  <!-- 内层的4个元素框架 -->
  <div id="tab-bar-item" @click="itemClick">
    <!-- 两张图片 一个文本 -->
    <div v-if="!isAction"><slot name="item-icon"></slot></div>
    <div v-else><slot name="item-icon-active"></slot></div>
    <div :style="activeStyle"><slot name="item-text"></slot></div>
  </div>
</template>

<script>
export default {
  props: {
    path: String,
    activeColor: {
      type: String,
      default: "red",
    },
  },
  methods: {
    itemClick() {
      this.$router.replace(this.path);
    },
  },
  computed: {
    isAction() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
    activeStyle() {
      return this.isAction ? { color: this.activeColor } : {};
    },
  },
};
</script>

<style scoped>
#tab-bar-item {
  flex: 1;
  text-align: center;
  height: 49px;
  font-size: 14px;
}

#tab-bar-item img {
  width: 24px;
  height: 24px;
  margin-bottom: 2px;
  vertical-align: middle;
}
</style>
